<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *奖励记录
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['sent']=1;
	if(!empty($_RQ['tasktitle'])){
		$params['tasktitle like']='%'.trim($_RQ['tasktitle']).'%';
		$return['params']['tasktitle']=$_RQ['tasktitle'];
	} 
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_renwu_task_reward',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$record=pdo_get('jy_renwu_task_record',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['recordid']));		
			$item['status']='进度:'.$record['task_progress'].'/'.$record['task_demand'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'任务记录'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'tasktitle','title'=>'任务名称','type'=>'string'),
			array('name'=>'tasktype','title'=>'任务类型','type'=>'radio','options'=>'tasktype'),
			array('name'=>'ownernickname','title'=>'发起人','type'=>'string'),
			array('name'=>'nickname','title'=>'奖励人','type'=>'string'),
			array('name'=>'sendtime','title'=>'奖励时间','type'=>'string'),
			array('name'=>'gettime','title'=>'领取时间','type'=>'string'),
			array('name'=>'reward_type','title'=>'奖励类型','type'=>'radio','options'=>'reward_type'),
			array('name'=>'status','title'=>'任务状态','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'tasktitle','title'=>'任务名称','type'=>'string','width'=>'40'),
		)
	);
	$return['reward_type']=array('credit1'=>'积分','credit2'=>'余额','red'=>'红包','reward_coupon'=>'优惠券','reward_goods'=>'商品');
	$return['tasktype']=array('poster'=>'海报任务','info_phone'=>'绑定手机','order_first'=>'首次购物','recharge_full'=>'单笔充值满额','order_full'=>'单笔满额','order_all'=>'累计消费','pyramid_money'=>'分销佣金','pyramid_num'=>'下级人数','comment'=>'商品好评','post'=>'社区发帖','goods'=>'购买指定商品','recharge_count'=>'累计充值满额');
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_renwu_task_record',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
